package com.example.demo;


import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
@RestController
@RequestMapping("/request")
public class Hello {

        //    cookie的传统获取
        @RequestMapping("/getCookies")
        public String getCookie(HttpServletRequest req) {
            Cookie[] cookies = req.getCookies();

//        lambda表达式
            if(cookies != null) {
                Arrays.stream(cookies).forEach(x -> System.out.println(x.getName()+":"+x.getValue()));
                return "获取Cookie成功！";
            }
            return "Cookie为空";
        }
}

